<?php

namespace App\Http\Controllers\safe;

use Illuminate\Http\Request;
use App\Models\Associator;
use App\Http\Controllers\Controller;
use Zhuzhichao\BankCardInfo\BankCard;

class SafeCenterController extends Controller
{
    //
    public function __construct()
    {
        $this->middleware('auth', [
            'except' => ['login', 'store']
        ]);
    }
     public function edit_pass(Request $request, Associator $user){
        if (\Hash::check($request['old_password'],$user->password)){
            if ($request['password']==$request['repassword'])
            {
                $user->update([
                   'password' => bcrypt($request['password'])
                ]);
                return redirect()->route('safe_center',$user)->with('msg','修改成功！');
            }else
                return redirect()->route('safe_center',$user)->with('msg','两次输入密码不一致！');
        } else
            return redirect()->route('safe_center',$user)->with('msg','密码不正确！');
     }
     public function edit_mobile(Request $request, Associator $user){
         if (\Hash::check($request['password'],$user->password)){
             $user->update([
                 'mobile' => $request['mobile']
             ]);
             return redirect()->route('safe_center',$user)->with('msg','修改成功！');
         } else
             return redirect()->route('safe_center',$user)->with('msg','密码不正确！');
     }
     public function edit_wechat(Request $request, Associator $user){
        $a = $user->update([
                'wechat' => $request['wechat']
        ]);
        if ($a)
            return redirect()->route('safe_center',$user)->with('msg','修改成功！');
        else
            return redirect()->route('safe_center',$user)->with('msg','修改失败！');
     }
    public function bound_card(Request $request, Associator $user){
        $bank = $request->request->all();
        $a = $user->update([
            'credit' => $bank['bank_id'],
            'name' => $bank['name'],
        ]);
        if ($a)
            return redirect()->route('safe_center',$user)->with('msg','绑定成功！');
        else
            return redirect()->route('safe_center',$user)->with('msg','绑定失败！');
    }
    public function get_card(Request $request){
        $id = $request->request->all();
        $data = BankCard::info($id['id']);
        return $data;
    }
}
